import { Component, OnInit } from '@angular/core'
import { NavigationEnd, Router } from '@angular/router'
import { filter } from 'rxjs'
import { UserAuthService } from '../@core/user-auth.service'

@Component({
  selector: 'app-login',
  templateUrl: './login.component.html',
  styleUrls: ['./login.component.scss']
})
export class LoginComponent implements OnInit {
  tabActiveId: string | number =
    location.href.indexOf('msgLogin') === -1 ? 'logins' : 'msgLogin'

  tabItems = [
    {
      id: 'msgLogin',
      title: '短信登录'
    },
    {
      id: 'logins',
      title: '密码登录'
    }
  ]

  constructor(public router: Router, private userAuthService: UserAuthService) {
    this.router.events
      .pipe(filter((event: any) => event instanceof NavigationEnd))
      .subscribe((event: any) => {
        let obj = this.tabItems.filter((item) => {
          return event.url.indexOf(item.id) != -1
        })
        if (obj.length) {
          this.tabActiveId = obj[0].id
        }
      })
  }

  ngOnInit(): void { }

  activeTabChange(tab) {
    this.router.navigate([`/login/${tab}`])
  }
}
